package com.gmail.viktor.yuryev.actions;

import com.gmail.viktor.yuryev.SSHClient;
import com.gmail.viktor.yuryev.model.ServerDetails;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.vfs.VirtualFile;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Viktor Yuryev on 4/10/2014.
 */
public class UploadToServerAction extends AnAction {
    private final ServerDetails details;

    public UploadToServerAction(ServerDetails details) {
        super(details.getHost());
        this.details = details;
    }

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        VirtualFile[] files = anActionEvent.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        List<String> strfiles= new ArrayList<String>();
        for (VirtualFile file : files) {
            strfiles.add(file.getPath());
        }

        SSHClient pr = new SSHClient(details);
        try {
            pr.connect();
            pr.upload(strfiles);
            pr.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
